package cn.vehicle.biz.impl;

import cn.vehicle.biz.SysUserBiz;
import cn.vehicle.domains.entity.SysUserEntity;
import cn.vehicle.domains.vo.sysUser.AddUserReq;
import cn.vehicle.domains.vo.sysUser.UpdateUserReq;
import cn.vehicle.exception.VehicleAccessException;
import cn.vehicle.service.SysUserService;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

@Service
public class SysUserBizImpl implements SysUserBiz {


    @Resource
    private SysUserService sysUserService;
    @Override
    public void addUser(AddUserReq req) {
        SysUserEntity sysUserEntity = new SysUserEntity();
        BeanUtils.copyProperties(req, sysUserEntity);
        sysUserEntity.setPassword("123456");
        sysUserService.addUser(sysUserEntity) ;
    }

    @Override
    public void updateUser(UpdateUserReq req) {
        SysUserEntity sysUserEntity = sysUserService.getUserById(req.getId());
        if (sysUserEntity == null) {
            throw VehicleAccessException.DATE_NOT_EXIST.newInstance("用户不存在");
        }
        SysUserEntity updateEntity = new SysUserEntity();
        BeanUtils.copyProperties(req, updateEntity);
        sysUserService.updateUser(updateEntity);

    }
}
